import { POST } from '../axios.config.js'
import { downloadInLink } from '@utility/utility'

const base = window.config.ip
const baseModule = 'rcdg-zbkh'
const indication = `${base}/${baseModule}/index-report`
// const org = `${base}/${baseModule}/org-report`
const eff = `${base}/${baseModule}/eff-report`
const share = `${base}/${baseModule}/effect-share-report` // 履职效果
const assessment = `${base}/${baseModule}/assessment` // 打分
const perform = `${base}/${baseModule}/perform` // 考核评分

// const report = `${base}/xn-report/index-view` // 报告

const URLS = {
  listIndexReportNeed: `${indication}/listIndexReportNeed`, // 获取履职能力需要填报时间列表
  listEffIndexReportNeed: `${indication}/listEffIndexReportNeed`, // 获取履职效果需要填报时间列表

  // 省直单位
  listReportCfg: `${indication}/listReportCfg`, // 获取考核方案列表
  listReportIndex: `${indication}/listReportIndex`, // 获取需要填报的指标列表

  // listOrgReportIndex: `${indication}/listOrgReportIndex`, //  获取指标推送列表 废弃

  listReportCfgIndex: `${indication}/listReportCfgIndex`, // 获取指标级别列表（一级指标、二级指标）
  getReportIndex: `${indication}/getReportIndex`, // 获取指标填报页面详情数据
  saveReportIndex: `${indication}/saveReportIndex`, // 保存指标填报内容
  saveBatchReportIndex: `${indication}/saveBatchReportIndex`, // 批量保存指标填报内容
  // listReportIndexDetail: `${indication}/listReportIndexDetail`, // 获取指标历史推送记录
  getPushProgress: `${indication}/getPushProgress`, // 获取指标推送进度
  continueReportIndex: `${indication}/continueReportIndex`, // 继续推送
  listProvincialOrgan: `${indication}/listProvincialOrgan`, // 获取评价单位列表
  downLoadOptionFile: `${indication}/skipValidation/downLoadOptionFile`, // 下载填报模板
  exportIndexPushData: `${indication}/skipValidation/exportIndexPushData`, // 下载填报模板
  recallIndexReport: `${indication}/recallIndexReport`, // 指标撤回

  // 绩效办

  getOrgPushProgress: `${eff}/getOrgPushProgress`, // 省直单位推送进度
  listIndexReportPush: `${eff}/listIndexReportPush`, // 指标视图监测列表
  listFollowIndexReportPush: `${eff}/listFollowIndexReportPush`, // 指标视图推送不符合项
  listOrgReportPush: `${eff}/listOrgReportPush`, // 单位视图监测推送列表
  listFollowOrgReportPush: `${eff}/listFollowOrgReportPush`, // 指标视图维度查询不符合单位数量
  listMonitorOrgReport: `${eff}/listMonitorOrgReport`, // 指标视图维度查询推送单位列表
  listMonitorIndexReport: `${eff}/listMonitorIndexReport`, // 指标视图维度查询指标列表
  getReportIndexDetails: `${eff}/getReportIndex`, // 履职能力指标推送记录详情
  updateReCallCfg: `${eff}/updateReCallCfg`, // 修改撤回配置时间周期

  // 重点任务
  getOrgTaskStat: `${eff}/getOrgTaskStat`, // 获取重点任务推送状态
  listOrgKeyTask: `${eff}/listOrgKeyTask`, // 获取重点任务推送单位列表
  getKeyTaskDetail: `${eff}/getKeyTaskDetail`, // 获取重点任务详情

  // 履职效果（共享指标）
  getEffectShareCount: `${share}/getOrgPushProgress`, // 效果共享指标进度
  listEffectShareReport: `${share}/listIndexReportPush`,
  getEffectReportIndexDetail: `${share}/getReportIndexDetail`,
  uploadExcelTemplate: `${share}/excelImpData`, // 通过EXCEL导入数据
  listEffectReportData: `${share}/listEffectReportData`,
  deleteEffectReportData: `${share}/deleteEffectReportData`,
  listProgressChart: `${share}/listProgressChart`, // 获取首页监测图数据
  listEffectReportOrg: `${share}/listEffectReportOrg`, // 获取共享指标推送未导入的单位列表
  updateEffectReportScore: `${share}/updateEffectReportScore`, // 更新共享指信息（分数、单位名称）
  addEffectReport: `${share}/addEffectReport`, // 添加单位共享考核分值记录

  // 绩效办填报步骤-操作
  getAssessIndexScore: `${assessment}/getAssessIndexScore`, // 查看省直单位指标考核分值
  updateAssessIndexScore: `${assessment}/updateAssessIndexScore`, // 修改省直单位指标考核分值
  listCrossDepartment: `${assessment}/listCrossDepartment`, // 获取跨部门评价统计信息

  startIndexAssess: `${assessment}/startIndexAssess`, // 结束指标填报，开始考核评分

  // 考核评分
  listOrgAssessResult: `${perform}/listOrgAssessResult`, // 获取省直单位得分排名列表
  listAssessIndexReport: `${perform}/listAssessIndexReport`, // 获取单位指标考核得分报表
  downLoadAssessReportExcel: `${perform}/skipValidation/downLoadAssessReportExcel`, // 导出指标考核报告

  // 考核评分-履职效果
  listEffOrgAssessResult: `${share}/listEffOrgAssessResult`, // 获取省直单位得分排名列表
  listEffectAssessIndex: `${share}/listEffectAssessIndex`, // 获取单位指标考核得分报表
  // downLoadAssessReportExcel: `${share}/skipValidation/downLoadAssessReportExcel`, // 导出指标考核报告

  // 审核流程
  sureIndexScore: `${perform}/sureIndexScore`, // 提交审批
  cancelInitApproval: `${perform}/cancelInitApproval`, // 撤回审批
  approvalPerform: `${perform}/approvalPerform`, // 报告（节点）审核
  listApprovalFlow: `${perform}/listApprovalFlow`, // 获取审核流程

  // 检视报告
  listOptionScoreAnalysis: `${perform}/listOptionScoreAnalysis`, // 获取考核指标分值统计分析详情
  getScoreAnalysis: `${perform}/getScoreAnalysis`, // 获取考核分值统计（最高分，最低分和平均分）
  listScoreDistribution: `${perform}/listScoreDistribution`, // 获取考核分数分布
  scoreRankAnalysis: `${perform}/scoreRankAnalysis`, // 获取考核分值排名变化分析
  submitApprovalPerform: `${perform}/submitApprovalPerform`, // 提交能力报告

  // 检视报告（履职效果）
  listOptionAssessIndex: `${share}/listOptionAssessIndex`, // 获取考核指标分值统计分析详情

  // word报告
  generateReport: `${perform}/generateReport`, // 生成履职能力监测报告
  getReportViewContent: `${perform}/getReportViewContent`, // 获取对应报告
  listReportView: `${perform}/listReportView`, // 获取单位报告状态
  releaseReportView: `${perform}/releaseReportView`, // 下发报告
}

// ---------------- 公共接口 -- start
// 获取履职能力需要填报时间列表
export const getLznlNeedPostYears = () =>
  POST(URLS.listIndexReportNeed, null, {
    headers: {
      hideLoading: true,
    },
  })

// 获取履职效果需要填报时间列表
export const getLzxgNeedPostYears = () =>
  POST(URLS.listEffIndexReportNeed, null, {
    headers: {
      hideLoading: true,
    },
  })
// ---------------- 公共接口 -- end

// ---------------- 省直单位-指标管理 -- start

// 获取考核方案列表
export const getOrgSchemeList = () => POST(URLS.listReportCfg)

// 获取指标推送列表
// pidName:一级指标名称
// indexName:二级指标名称
export const getOrgIndicationList = (
  { busId, pidName, keywords, status, optionId, isBonus },
  currentPage = 1,
  pageSize = 0
) =>
  POST(URLS.listReportIndex, {
    param: {
      busId,
      pidName,
      keywords,
      status,
      optionId,
      isBonus,
    },
    currentPage,
    pageSize,
  })

// 获取指标级别列表（一级指标、二级指标）
export const getIndicationLevels = (busId, type) =>
  POST(URLS.listReportCfgIndex, {
    busId,
    type,
  })

// 获取指标填报页面详情数据
export const getReportDetails = id =>
  POST(URLS.getReportIndex, {
    id,
  })

// 保存指标填报内容
// 0 暂存， 1 提交
export const saveIndPushData = (id, optionList) =>
  POST(URLS.saveReportIndex, {
    id,
    optionFillList: optionList,
    status: '1',
  })

// 保存指标填报内容
// 0 暂存， 1 提交
export const saveIndPushDataTemp = (id, optionList) =>
  POST(
    URLS.saveReportIndex,
    {
      id,
      optionFillList: optionList,
      status: '0',
    },
    {
      headers: {
        hideLoading: true,
      },
    }
  )

// 批量保存指标填报内容
// 0 暂存， 1 提交
export const saveIndPushDataBatch = (optionId, reportIndexList, isSecret) =>
  POST(URLS.saveBatchReportIndex, {
    optionId,
    reportIndexList,
    isSecret: (isSecret && '1') || '0',
    status: '1',
  })

// 批量保存指标填报内容
// 0 暂存， 1 提交
export const saveIndPushDataTempBatch = (optionId, reportIndexList, isSecret) =>
  POST(
    URLS.saveBatchReportIndex,
    {
      optionId,
      reportIndexList,
      isSecret: (isSecret && '1') || '0',
      status: '0',
    },
    {
      headers: {
        hideLoading: true,
      },
    }
  )

// // 获取指标填报推送历史
// export const getIndPostRecords = id =>
//   POST(URLS.listReportIndexDetail, {
//     id,
//   })

// 获取指标填报推送进度
export const getPushProgress = id =>
  POST(URLS.getPushProgress, {
    id,
  })

// 继续推送
export const continueReportIndex = id =>
  POST(URLS.continueReportIndex, {
    id,
  })

// 获取评价单位列表
export const listProvincialOrgan = () => POST(URLS.listProvincialOrgan)

// 获取评价单位列表
export const downLoadOptionFile = optionId => {
  const href = `${URLS.downLoadOptionFile}?optionId=${optionId}` // 导出文件
  downloadInLink(href)
}

// ---------------- 省直单位-指标管理 -- end

// ---------------- 绩效办-指标管理 -- start

// 省直单位推送进度
// type 1.指标维度统计 2.省直单位维度统计
export const getIndPushProgress = (busId, isOrg) =>
  POST(URLS.getOrgPushProgress, {
    busId,
    type: (isOrg && '2') || '1',
  })

// 获取共享指标（履职效果、履职能力）推送状态数量
export const getEffectShareCount = busId =>
  POST(URLS.getEffectShareCount, {
    busId,
  })

// 指标视图-获取指标列表
// isBonus: 0：必须推送项,1：加分项
export const getIndViewIndications = ({ busId, keywords, status, optionId, isBonus }, currentPage = 1, pageSize = 10) =>
  POST(URLS.listIndexReportPush, {
    currentPage,
    pageSize,
    param: {
      busId,
      keywords,
      status,
      optionId,
      isBonus,
    },
  })

// 获取共享指标（履职效果、履职能力）列表
export const listEffectShareReport = ({ busId, keywords, status, pidName, optionId }, currentPage = 1, pageSize = 10) =>
  POST(URLS.listEffectShareReport, {
    currentPage,
    pageSize,
    param: {
      busId,
      keywords,
      status,
      pidName,
      optionId,
    },
  })

// 指标视图-单位列表
// status: -1 不符
export const getIndViewOrgs = ({ optionId, keywords, status, orgId, pid }, currentPage = 1, pageSize = 10) =>
  POST(URLS.listMonitorOrgReport, {
    currentPage,
    pageSize,
    param: {
      optionId,
      keywords,
      status,
      orgId,
      pid,
    },
  })

// 指标视图-推送不符合项
export const getIndViewInvalids = ({ busId, keywords, isBonus }, currentPage = 1, pageSize = 10) =>
  POST(URLS.listFollowIndexReportPush, {
    currentPage,
    pageSize,
    param: {
      busId,
      keywords,
      isBonus,
      type: '1', // 首页检测列表
    },
  })

// 单位视图-单位列表
// pidName 指标名称
// pid 单位上级id
export const getOrgViewOrgs = ({ busId, keywords, status, pidName, orgId, pid }, currentPage = 1, pageSize = 10) =>
  POST(URLS.listOrgReportPush, {
    currentPage,
    pageSize,
    param: {
      busId,
      keywords,
      status,
      pidName,
      orgId,
      pid,
    },
  })

// 单位视图-获取指标列表
export const getOrgViewIndications = ({ busId, orgId, pidName, keywords, status }, currentPage = 1, pageSize = 10) =>
  POST(URLS.listMonitorIndexReport, {
    currentPage,
    pageSize,
    param: {
      busId,
      orgId,
      pidName,
      keywords,
      status,
    },
  })

// 单位视图-获取不符合单位列表
export const getOrgViewInvalids = ({ busId, orgId }, currentPage = 1, pageSize = 10) =>
  POST(URLS.listFollowOrgReportPush, {
    currentPage,
    pageSize,
    param: {
      busId,
      orgId,
    },
  })

// 履职能力指标推送记录详情
export const getLznlIndDetails = (optionId, orgId) =>
  POST(URLS.getReportIndexDetails, {
    optionId,
    orgId,
  })

// 修改撤回配置时间周期
export const submitRollbackTime = (busId, recallStart, recallEnd) =>
  POST(URLS.updateReCallCfg, {
    busId,
    recallStart,
    recallEnd,
  })

// 重点任务
// 获取重点任务推送状态
export const getOrgTaskStat = busId =>
  POST(URLS.getOrgTaskStat, {
    oneParam: busId,
  })
// 获取重点任务推送单位列表
export const listOrgKeyTask = (busId, status, currentPage = 1, pageSize = 0) =>
  POST(URLS.listOrgKeyTask, {
    currentPage,
    pageSize,
    param: {
      busId,
      status,
    },
  })
// 获取重点任务推送单位列表
export const getKeyTaskDetail = (busId, orgId) =>
  POST(URLS.getKeyTaskDetail, {
    busId,
    orgId,
  })

// 共享指标推送记录详情
export const getIndShareDetails = id =>
  POST(URLS.getEffectReportIndexDetail, {
    id,
  })

// 通过EXCEL导入数据
export const uploadExcelTemplate = (optionId, files) => {
  const formData = new FormData()
  formData.append('optionId', optionId)
  formData.append('files', files)
  return POST(URLS.uploadExcelTemplate, formData)
}

// 获取共享指标导入数据后的列表数据
export const listEffectReportData = ({ optionId, keywords, orgId }, currentPage = 1, pageSize = 10) =>
  POST(URLS.listEffectReportData, {
    currentPage,
    pageSize,
    param: {
      optionId,
      keywords,
      orgId,
    },
  })

// 获取共享指标推送未导入的单位列表
export const getShareIndNoCheckedOrgs = id => POST(URLS.listEffectReportOrg, { id })

// 删除评分指标
export const deleteEffectReportData = id => POST(URLS.deleteEffectReportData, { id })

// 更新共享指信息（分数、单位名称）
export const updateIndShareInfo = ({ id, optionId, indexScore, orgName }) =>
  POST(
    URLS.updateEffectReportScore,
    {
      id,
      optionId,
      indexScore,
      orgName,
    },
    {
      headers: {
        hideLoading: true,
      },
    }
  )

// 添加单位共享考核分值记录
export const addEffectReport = ({ optionId, orgId, orgName, indexScore = 0, scoreResult = 0 }) =>
  POST(
    URLS.addEffectReport,
    {
      optionId,
      orgId,
      orgName,
      indexScore,
      scoreResult,
    },
    {
      headers: {
        hideLoading: true,
      },
    }
  )

// 获取首页监测图数据
export const getLzxgProgressChart = busId =>
  POST(URLS.listProgressChart, {
    oneParam: busId,
  })

// ---------------- 绩效办-指标管理 -- end

// 考核评分-----

// 查看省直单位指标考核分值
export const getOrgIndScore = (optionId, orgId) =>
  POST(URLS.getAssessIndexScore, {
    optionId,
    orgId,
  })

// 修改省直单位指标考核分值
export const updateOrgIndScore = ({ id, bonusScore, incScore, lackScore, timeScore, indexScore, remark }) =>
  POST(URLS.updateAssessIndexScore, {
    id,
    bonusScore,
    incScore,
    lackScore,
    timeScore,
    indexScore,
    remark,
  })

// 获取跨部门评价统计信息
export const getOrgEvalInfo = (busId, orgId) =>
  POST(URLS.listCrossDepartment, {
    orgId,
    busId,
  })

// 停止指标填报
export const stopIndPush = busId =>
  POST(URLS.startIndexAssess, {
    id: busId,
  })

// ----履职能力 考核评分
// 获取省直单位得分排名列表
export const getIndOrgScoreRank = (busId, currentPage = 1, pageSize = 10) =>
  POST(URLS.listOrgAssessResult, {
    currentPage,
    pageSize,
    param: {
      busId,
    },
  })

// 获取单位指标考核得分报表
export const getIndOrgScoreDetails = ({ busId, orgId }) =>
  POST(URLS.listAssessIndexReport, {
    busId,
    orgId,
  })

// 导出指标考核报告
export const downLoadOrgScoreReport = (busId, orgId) => {
  const href = `${URLS.downLoadAssessReportExcel}?busId=${busId}&orgId=${orgId}` // 导出文件
  downloadInLink(href)
}

// ---履职效果--考核评分
// 获取省直单位得分排名列表
// export const getIndShareOrgScoreRank = (busId, currentPage = 1, pageSize = 10) =>
//   POST(URLS.listEffOrgAssessResult, {
//     currentPage,
//     pageSize,
//     param: {
//       busId,
//     },
//   })

// 获取单位指标考核得分报表
export const getIndShareOrgScoreDetails = (busId, orgId) =>
  POST(URLS.listEffectAssessIndex, {
    busId,
    orgId,
  })

// 导出指标考核报告
export const downLoadOrgShareScoreReport = (busId, orgId) => {
  const href = `${URLS.downLoadAssessReportExcel}?busId=${busId}&orgId=${orgId}` // 导出文件
  downloadInLink(href)
}

// 确认考核评分
export const sureIndexScore = id =>
  POST(URLS.sureIndexScore, {
    id,
  })

// 取消审批
export const cancelInitApproval = (busId, scence) =>
  POST(URLS.cancelInitApproval, {
    busId,
    type: scence,
  })

// 报告审核
export const approvalPerform = (busId, approvalStatus, reason) =>
  POST(URLS.approvalPerform, {
    busId,
    approvalStatus,
    reason,
  })

// 获取审核流程记录
export const listApprovalFlow = id =>
  POST(URLS.listApprovalFlow, {
    id,
  })

// 检视报告

// 获取考核分值统计（最高分，最低分和平均分）
export const getScoreAnalysis = busId =>
  POST(URLS.getScoreAnalysis, {
    busId,
  })

// 获取考核指标分值统计分析详情
export const listOptionScoreAnalysis = busId =>
  POST(URLS.listOptionScoreAnalysis, {
    busId,
  })

// 获取考核分数分布
export const listScoreDistribution = busId =>
  POST(URLS.listScoreDistribution, {
    busId,
  })

// 获取考核分值排名变化分析
export const scoreRankAnalysis = busId =>
  POST(URLS.scoreRankAnalysis, {
    busId,
  })

// 提交能力报告
export const submitApprovalPerform = id =>
  POST(URLS.submitApprovalPerform, {
    id,
  })

// 导出指标考核报告
export const downLoadOrgIndInfo = (optionId, orgId) => {
  const href = `${URLS.exportIndexPushData}?optionId=${optionId}&orgId=${orgId}` // 导出文件
  downloadInLink(href)
}

// 指标撤回
export const rollbackIndPost = id =>
  POST(URLS.recallIndexReport, {
    id,
  })

// 履职效果---检视报告

// 获取考核指标分值统计分析详情
export const listOptionAssessIndex = busId =>
  POST(URLS.listOptionAssessIndex, {
    busId,
  })

// word 报告

// 生成监测报告
export const generateIndReport = id =>
  POST(URLS.generateReport, {
    id,
  })

// 获取报告内容
export const getIndReportViewContent = (viewId, orgId) =>
  POST(URLS.getReportViewContent, {
    viewId,
    orgId,
  })

// 获取单位报告状态
export const listOrgReportView = viewId =>
  POST(URLS.listReportView, {
    viewId,
  })

// 下发报告
export const releaseReport = (viewId, orgIds) =>
  POST(URLS.releaseReportView, {
    viewId,
    busId: orgIds,
  })
